<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期选择器 - 组件演示</title>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../components/datepicker/datepicker.css">
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🚀 openHarmony_Cordova_NutpiDesign</h1>
            <p class="subtitle">组件演示 - 日期选择器</p>
        </header>

        <nav class="demo-nav">
            <a href="../index.html" class="nav-back">← 返回首页</a>
        </nav>

        <main class="main-content">
            <section class="demo-section">
                <h2>📅 日期选择器演示</h2>
                
                <div class="demo-container">
                    <div class="demo-item">
                        <h3>单日期选择</h3>
                        <div id="singleDatePicker"></div>
                        <p class="demo-result">选择的日期: <span id="singleResult">未选择</span></p>
                    </div>

                    <div class="demo-item">
                        <h3>日期范围选择</h3>
                        <div id="rangeDatePicker"></div>
                        <p class="demo-result">选择的范围: <span id="rangeResult">未选择</span></p>
                    </div>

                    <div class="demo-item">
                        <h3>带限制的日期选择</h3>
                        <div id="limitedDatePicker"></div>
                        <p class="demo-result">选择的日期: <span id="limitedResult">未选择</span></p>
                    </div>
                </div>
            </section>

            <section class="demo-section">
                <h2>使用代码</h2>
                <pre><code>// 1. 引入文件
&lt;link rel="stylesheet" href="components/datepicker/datepicker.css"&gt;
&lt;script src="components/datepicker/datepicker.js"&lt;/script&gt;

// 2. 创建容器
&lt;div id="datePickerContainer"&lt;/div&gt;

// 3. 初始化日期选择器
const datePicker = new DatePicker({
    container: '#datePickerContainer',
    type: 'single',  // single 或 range
    onChange: (value) => {
        console.log('选择的日期:', value);
    }
});

// 4. 获取选择的日期
const value = datePicker.getValue();

// 5. 设置日期
datePicker.setValue('2025-01-15');</code></pre>
            </section>
        </main>

        <footer class="footer">
            <p>&copy; 2025 OpenHarmony 三方库适配中心 | MIT License</p>
        </footer>
    </div>

    <script src="../components/datepicker/datepicker.js"></script>
    <script>
        // 单日期选择
        const singlePicker = new DatePicker({
            container: '#singleDatePicker',
            type: 'single',
            onChange: (date) => {
                document.getElementById('singleResult').textContent = date;
            }
        });

        // 日期范围选择
        const rangePicker = new DatePicker({
            container: '#rangeDatePicker',
            type: 'range',
            onChange: (range) => {
                if (range.startDate && range.endDate) {
                    document.getElementById('rangeResult').textContent = 
                        `${range.startDate} 至 ${range.endDate}`;
                }
            }
        });

        // 带限制的日期选择
        const today = new Date();
        const minDate = new Date(today);
        minDate.setDate(minDate.getDate() - 30);
        const maxDate = new Date(today);
        maxDate.setDate(maxDate.getDate() + 30);

        const formatDate = (date) => {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            return `${year}-${month}-${day}`;
        };

        const limitedPicker = new DatePicker({
            container: '#limitedDatePicker',
            type: 'single',
            minDate: formatDate(minDate),
            maxDate: formatDate(maxDate),
            onChange: (date) => {
                document.getElementById('limitedResult').textContent = date;
            }
        });
    </script>

    <style>
        .demo-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .demo-item {
            background: var(--bg-light);
            padding: 16px;
            border-radius: 8px;
        }

        .demo-item h3 {
            margin-top: 0;
            margin-bottom: 16px;
            font-size: 16px;
            color: var(--text-primary);
        }

        .demo-result {
            margin-top: 12px;
            padding: 8px 12px;
            background: var(--bg-white);
            border-radius: 4px;
            font-size: 13px;
            color: var(--text-secondary);
        }

        .demo-result span {
            color: var(--primary-color);
            font-weight: 600;
        }

        @media (max-width: 768px) {
            .demo-container {
                grid-template-columns: 1fr;
            }
        }
    </style>
</body>
</html>
